<template>
  <page-header-wrapper>
    <application-search
      :filterFields="[
        'BeviewResult',
        'CityVfyAgent',
        'ApplyClass',
        'CityVfyAssign',
        'SubmitToCity',
        'ProcessDate',
        'ProcessUser',
        'CityVfyDate',
        'VerifyResult',
        'CityVfyResult',
        'CityRfyDate',
        'CityRfyResult',
      ]"
      @search="handleSearch"
      @reset="handleReset"
    >
    </application-search>
    <a-card :bordered="false">
      <div class="table-header m-b-24"></div>
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
          <y-button type="link" @click="handleEdit(record.ID)"> 修改 </y-button>
          <a-popconfirm title="确认删除此信息？" placement="left" @confirm="handleDel(record)">
            <y-button type="link" class="text-error">删除</y-button>
          </a-popconfirm>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, applicationSearch } from '@/components'
import { getProposerList, postProposerExamine } from '@/api/common'
import moment from 'moment'
export default {
  components: {
    STable,
    Ellipsis,
    applicationSearch,
  },
  data() {
    this.$eventBus.$on('informationInputRefresh', (refresh) => {
      this.$refs.table.refresh(refresh)
    })
    return {
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'EnterpriseFiling',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          customRender: (text, record, index) => <span>{index + 1}</span>,
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        {
          title: '申请类别',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '所属区级',
          align: 'center',
          dataIndex: 'RegionName',
        },
        {
          title: '所属企业',
          align: 'center',
          dataIndex: 'TownshipName',
        },
        {
          title: '操作',
          align: 'center',
          fixed: 'right',
          width: 180,
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getProposerList(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.$refs.table.refresh(true)
    },
    handleDel(record) {
      const { ID, ApplyNo } = record
      this.$loading.show({
        tip: '删除中，请稍后...',
      })
      postProposerExamine({
        State: 'zxbaOut',
        ProposerModules: {
          ApplyNo,
          ID,
          LastAlterUserID: this.$store.getters.userid,
          LastAlterDate: moment().format('YYYY-MM-DD'),
        },
      })
        .then((res) => {
          this.$message.success('删除成功！')
          this.$refs.table.refresh()
        })
        .finally(() => {
          this.$loading.hide()
        })
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'recordByOneSelfDetail',
        params: {
          id,
        },
      })
    },
    handleEdit(id) {
      localStorage.setItem('browserCacheEdit', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'recordByOneSelfEdit',
        params: {
          id,
        },
      })
    },
    handleAudit(id) {
      this.$router.push({
        name: 'assureInformationAudit',
        params: {
          id,
          type: 'community',
        },
      })
    },
  },
}
</script>
<style lang="less" scoped>
.table-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
